package com.polaris.live.widget

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.RelativeLayout
import com.blankj.utilcode.util.ColorUtils
import com.polaris.live.R
import com.polaris.live.common.R.*
import com.polaris.live.databinding.WidgetSexAgeBinding
import com.polaris.live.utils.CommonUtils

/**
 * 性别年龄控件
 *
 * @author Created by lucas on 2023/10/22 16:20
 * @since 1.0.0
 */
class SexAgeView(context: Context, attributeSet: AttributeSet) :
    RelativeLayout(context, attributeSet) {

    private val mBinding = WidgetSexAgeBinding.inflate(LayoutInflater.from(context), this)

    /**
     * 设置性别和年龄
     */
    fun setSexAndAge(sex: Int, birthday: Long?) {
        if (birthday != null) {
            visibility = VISIBLE

            if (CommonUtils.isMan(sex)) {
                mBinding.spAge.setBackgroundResource(R.drawable.sex_age_man_back)
                mBinding.ivSex.setImageResource(R.drawable.ic_man)
                mBinding.tvAge.setTextColor(ColorUtils.getColor(color.color_58baf9))
            } else {
                mBinding.spAge.setBackgroundResource(R.drawable.sex_age_woman_back)
                mBinding.ivSex.setImageResource(R.drawable.sex_woman)
                mBinding.tvAge.setTextColor(ColorUtils.getColor(color.color_ff93f1))
            }

            mBinding.tvAge.text = CommonUtils.getAge(birthday).toString()
        } else {
            visibility = GONE
        }
    }

    fun setSexTextSize(size: Float) {
        mBinding.tvAge.textSize = size
    }

}